<?php
class SettingController extends MController {
    
    public function indexAction(){
        $form = new SettingsForm();
        $this->render('index', array('form'=>$form));
    }
    
    public function defaultAction(){
        if ($this->getRequest()->isPost()){
            $post = $this->getRequest()->getPost();
            print_r($post);
            foreach ($post as $key=>$value){
                if (($setting = Setting::first(array('name'=>$key))) != NULL){
                    $setting->value = $value;
                    $setting->save();
                } else {
                    Setting::create(array('name'=>$key, 'value'=>$value));
                }
            }
            MRequest::redirect(__route('ml-admin/setting'));
        } else {
            MRequest::redirect(__route('ml-admin/setting'));
        }
    }
}
?>
